package myPetStore.web.servlet;

import myPetStore.domain.Account;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class RegisterFormServlet extends HttpServlet {
    private static final String  REGISTER_FORM="/WEB-INF/jsp/account/register.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Account tempAccount=new Account();
        intiAccount(tempAccount);
        HttpSession session=req.getSession();
        session.setAttribute("tempAccount",tempAccount);
        session.setAttribute("repeatPassword","");
        req.getRequestDispatcher(REGISTER_FORM).forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
    private void intiAccount(Account account){
        account.setUsername("");
        account.setPassword("");
        account.setFirstName("");
        account.setLastName("");
        account.setEmail("");
        account.setCountry("");
        account.setState("");
        account.setCity("");
        account.setAddress1("");
        account.setAddress2("");
        account.setZip("");
        account.setPhone("");
        account.setFavouriteCategoryId("");
    }
}
